//
//  SLDeployBoatsCollectionViewCell.m
//  StarLight
//
//  Created by 吴涛 on 16/5/30.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLDeployBoatsCollectionViewCell.h"


@interface SLDeployBoatsCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *refreshBtn;
@property (weak, nonatomic) IBOutlet UIButton *setBtn;
@property (weak, nonatomic) IBOutlet UILabel *boatNameLB;
@property (weak, nonatomic) IBOutlet UILabel *boatStatusLB;
@property (weak, nonatomic) IBOutlet UILabel *currentLocLB;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (weak, nonatomic) IBOutlet UIButton *recomBtn;
@property (weak, nonatomic) IBOutlet UILabel *tipCurrentLocLB;
@property (weak, nonatomic) IBOutlet UILabel *tipRecomLb;
@property (nonatomic, strong) SLDeployShip *shipModel;
@property (nonatomic, strong) UIImageView *shipStatusImageView;

@end


@implementation SLDeployBoatsCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
  self.recomBtn.layer.cornerRadius = 5;
  self.recomBtn.backgroundColor = [UIColor lightGrayColor];
  self.refreshBtn.backgroundColor = SLYellowColor;
  self.setBtn.backgroundColor = SLYellowColor;
  self.countLabel.textColor = SLYellowColor;
  self.countLabel.font = [UIFont systemFontOfSize:18];
  self.backgroundColor = [UIColor whiteColor];
  self.layer.cornerRadius = 5.f;
  
  self.shipStatusImageView = [UIImageView new];
  [self addSubview:self.shipStatusImageView];
  [self.shipStatusImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(self.boatStatusLB);
    make.left.equalTo(self.boatStatusLB.mas_right).offset(10);
    make.size.mas_equalTo(CGSizeMake(25, 25));
  }];
  
}


- (void)configDeployBoatCellWithModel:(SLDeployShip *)model{
  [self notHidden];
  self.shipModel = model;
  self.boatNameLB.text = model.boatname;
  self.countLabel.text = [NSString stringWithFormat:@"%ld",(long)model.matchs];
  self.currentLocLB.text = model.shiploc;
  
  switch (model.state) {
    case 0:{
      //满载
      self.boatStatusLB.text = @"满载";
      self.shipStatusImageView.image = [UIImage imageNamed:@"Full load"];
      [self changeHidden];
    }
      break;
    case 1:{
      //空船找货
      self.boatStatusLB.text = @"空船找货";
      self.shipStatusImageView.image = [UIImage imageNamed:@"Find goods"];
    }
      break;
    case 2:{
      //半船找货
      self.boatStatusLB.text = @"半船找货";
      self.shipStatusImageView.image = [UIImage imageNamed:@"半船找货"];
    }
      break;
    case 3:{
      //预定货物
      self.boatStatusLB.text = @"预定货物";
      self.shipStatusImageView.image = [UIImage imageNamed:@"预定货物"];
      self.currentLocLB.text = model.goalloc;
      
    }
      break;
      
    default:
      break;
  }

}

- (void)changeHidden{
  [self.recomBtn setImage:[UIImage imageNamed:@"boat"] forState:UIControlStateNormal];
  self.recomBtn.backgroundColor = [UIColor clearColor];
  self.recomBtn.enabled = NO;
  self.tipRecomLb.hidden = YES;
  self.countLabel.hidden = YES;
  self.tipCurrentLocLB.hidden = YES;
  self.currentLocLB.hidden = YES;
  
}

- (void)notHidden{
  self.recomBtn.enabled = YES;
  self.recomBtn.backgroundColor = [UIColor lightGrayColor];
  [self.recomBtn setImage:nil forState:UIControlStateNormal];
  self.recomBtn.imageView.image = nil;
  self.tipRecomLb.hidden = NO;
  self.countLabel.hidden = NO;
  self.tipCurrentLocLB.hidden = NO;
  self.currentLocLB.hidden = NO;
}



#pragma mark - Private Methods

- (IBAction)setAction:(id)sender {
  
  if (_delegate && [_delegate respondsToSelector:@selector(didTapedSetBtn:)]) {
   [_delegate didTapedSetBtn:self.shipModel];
  }
  
}
- (IBAction)refreshAction:(id)sender {
  
  if (_delegate && [_delegate respondsToSelector:@selector(didTapedRefreshBtn:)]) {
    
     [_delegate didTapedRefreshBtn:self.shipModel];
  }
}

- (IBAction)matchAction:(id)sender {
  if (self.shipModel.matchs != 0) {
    if (_delegate && [_delegate respondsToSelector:@selector(didTapedRecomBtn:)]) {
      [_delegate didTapedRecomBtn:self.shipModel];
    }
  }else{
    
    [SVProgressHUD showImage:nil status:@"暂无推荐货源"];
  }
  
  
}






@end
